<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui"
      xmlns:ui="http://java.sun.com/jsf/facelets"> 

<h:head> 	
	<title>TravelDream Modifica Profilo</title>
</h:head> 
<h:body onload="#{utenteManagedBean.fillListaPacchetti()}"> 
	<h:form>      
	    <p:menubar>
	    	<p:menuitem value="Homepage" icon="ui-icon-contact" url="home.xhtml?faces-redirect=true"/> 
	         
	        <f:facet name="options">
	        	<p:outputLabel value="Benvenuto, #{utenteManagedBean.nome}" style="margin-right:10px"/>  
	            <p:commandButton value="Modifica Profilo" icon="ui-icon-contact" action="modifica_utente.xhtml?faces-redirect=true"/>
	            <p:commandButton value="Logout" icon="ui-icon-extlink" action="#{loginManagedBean.logout()}"/>  
	        </f:facet>  
	    </p:menubar>  
  	</h:form>
        <h:form id="modificaUtente">	
        <p:message for="nome"/>
         <p:message redisplay="false" for="cf" style="margin:0.5em"/>
         <p:message redisplay="false" for="cognome" style="margin:0.5em"/>
		<p:message redisplay="false" for="oldpwd" style="margin:0.5em"/>
		<p:message redisplay="false" for="confirmNewPwd" showDetail="true" style="margin:0.5em"/>  
         <p:message redisplay="false" for="newpwd" showDetail="true" style="margin:0.5em"/>   
			<p:panel header = "Dati utente" id = "DatiUtente" style = "float:left; margin:0.5em; min-width: 500px;"> 
	            
	            <p:inputText id="nome" value="#{utenteManagedBean.modificaProfiloDTO.nome}" requiredMessage="Inseririsci un nome" style="float:right; margin-top:0.5em"/>
	            <p:outputLabel value="Nome:" style="float:right; margin-right: 0.5em; margin-top:0.5em"/>
	             

	           	<p:inputText id="cognome" value="#{utenteManagedBean.modificaProfiloDTO.cognome}" requiredMessage="Inseririsci il cognome" style="float:right; clear:both"/>
			    <p:outputLabel value="Cognome:" style="float:right; margin-right: 0.5em"/>
			    

	        	<p:inputText id="cf" value="#{utenteManagedBean.modificaProfiloDTO.codiceFiscale}" requiredMessage="Inseririsci il codice fiscale" style="float:right; clear:both"
	        	 validator="prime.CFValidator" validatorMessage="Codice finscale non valido"/>

				<p:outputLabel value="Codice fiscale:" style="float:right; margin-right: 0.5em"/>

	            <p:password id="oldpwd" value="#{utenteManagedBean.vecchiaPassword}" requiredMessage="Inseririsci la vecchia Password" style="float:right; clear:both"/>

	            <p:outputLabel value="Vecchia password:" style="float:right; margin-right: 0.5em"/>

	            <p:password id="newpwd" label="Nuova Password" feedback="true" match="confirmNewPwd"
	            value="#{utenteManagedBean.nuovaPassword}" requiredMessage="Inseririsci la nuova Password"
	            style="float:right; clear:both" />
	            
    	        <p:outputLabel value="Nuova password:" style="float:right; margin-right: 0.5em"/>

	            <p:password id="confirmNewPwd" label = "Conferma password"
	            value="#{utenteManagedBean.modificaProfiloDTO.nuovaPassword}"
	            requiredMessage="Inseririsci la nuova Password" style="float:right; clear:both"
	            validator="prime.passwordValidatorPerModifica" validatorMessage="La password deve contenere almeno una lettera ed un numero ed essere compresa tra 8 e 32 caratteri"
	            />
	            
	            <p:outputLabel value="Conferma nuova password:"  style="float:right; margin-right: 0.5em"/>
               
                <p:commandButton value="Modifica Profilo" action="#{utenteManagedBean.modificaProfilo()}"
                               style="clear:both; float:left;" ajax="false"/>
			</p:panel>
		</h:form>
		<!-- pannello dati pacchetti -->
		    <h:form>         
  			<p:panel id = "DatiPacchetti" header = "Pacchetti acquistati" style = "float:left; width:auto; margin:0.5em">
	        	<p:dataTable id="searchOutput" var="p" value="#{utenteManagedBean.pacchettiAcquistati}">
					<p:column headerText="Immagine">
	               		<img style="width:100px" src="../resources/TdTheme/img/hotel.png"/>
	           		</p:column>
		
					<p:column headerText="Nome">
	                 <h:outputText value="#{p.originante.nome}"/>
	             	</p:column>
	             
		             <p:column headerText="Destinazione">
		                 <h:outputText value="#{p.originante.destinazione_pacchetto}"/>
		             </p:column>
		             
		             <p:column headerText="Data di partenza">
		             	<h:outputText value="#{p.dataPartenza}" ><f:convertDateTime pattern="dd/MM/yyyy"  timeZone="Europe/Rome"/></h:outputText>
		             </p:column>
		             
		             <p:column>
	             		<p:commandButton value="Dettagli" action="#{personalizzazioneManagedBean.modificaDopoAcquisto(p)}" rendered="#{!p.utilizzato}"/>
	             		<p:outputLabel rendered="#{p.utilizzato}">Pacchetto Utilizzato</p:outputLabel>
		             </p:column>	 
		        </p:dataTable>
	     	</p:panel>
	     </h:form>           
</h:body> 
</html>
